package com.industrial.premu.components.strategy;

import com.alibaba.excel.util.StringUtils;
import com.industrial.premu.components.strategy.impl.gs.GsTongJiJuStrategyImpl;
import com.industrial.premu.enums.DeptCodeEnums;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

public class XlsxImportContext {

    private final Map<String, ImportStrategy> strategyMap = new HashMap<>();

    public XlsxImportContext() {
        strategyMap.put(DeptCodeEnums.GS_TJJ,new GsTongJiJuStrategyImpl());
    }

    /**
     * 导入Xlsx数据
     * @param deptCode 部门名称
     * @param file 文件
     * @param year 年份
     * @param companyType 企业类型
     */
    public void importXlsx(String deptCode, MultipartFile file,String year,String companyType){
        ImportStrategy importStrategy = strategyMap.get(deptCode);
        if(importStrategy == null){
            throw new RuntimeException("没有找到导入策略类");
        }
        String error = importStrategy.validate(file);
        if(StringUtils.isNotBlank(error)){
            throw new RuntimeException(error);
        }
    }
}
